<include file="public@header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Stuff/index')}">材料库</a></li>
        <li><a href="{:url('Stuff/add')}">新增材料</a></li>
        <li class="active"><a href="{:url('Stuff/edit',array('id'=>$id))}">编辑材料</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form" action="{:url('Stuff/edit_post')}">
        <fieldset>
            <input type="hidden" name="id" value="{$id}">
            <div class="control-group">
                <label class="control-label">材料名称</label>
                <div class="controls">
                    <input type="text" name="stuff_name" class="form-control" value="{$stuff_name}" required/>
                    <span class="form-required">*</span>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">类型</label>
                <div class="controls">
                    <select name="cate_id" class="form-control">
                        <volist name="cate" id="vo">
                            <option value="{$vo.id}"
                            <if condition="$cate_id eq $vo.id">selected</if>
                            >{$vo.cate_name}</option>
                        </volist>
                    </select>
                    <span class="form-required">*</span>
                </div>
            </div>
            <div class="control-group normal">
                <label class="control-label">价格</label>
                <div class="controls">
                    <input type="text" name="stuff_money" value="{$stuff_money}" class="form-control"
                           onInput="clearNoNum(this)" required/>
                    <span class="form-required">*</span>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">单位</label>
                <div class="controls">
                    <select name="stuff_unit" class="form-control">
                        <option value="立方价"<if condition="$stuff_unit eq '立方价'">selected</if>>立方价</option>
                        <option value="平方价"
                        <if condition="$stuff_unit eq '平方价'">selected</if>
                        >平方价</option>
                        <option value="吨"
                        <if condition="$stuff_unit eq '吨'">selected</if>
                        >吨</option>
                        <option value="公斤"
                        <if condition="$stuff_unit eq '公斤'">selected</if>
                        >公斤</option>
                    </select>
                    <span class="form-required">*</span>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">排序</label>
                <div class="controls">
                    <input name="list_order" type='text' size='3' value='{$list_order}' class="form-control" required>
                    <span class="form-required">*</span>
                </div>
            </div>
            <div class="control-group">
                <table class="table table-bordered">
                    <label class="control-label">{:lang('ROCK_IMG')}</label>
                    <div class="controls">
                        <input type="hidden" name="stuff_image" id="thumb" value="{$result.stuff_image|default=''}">
                        <a href="javascript:uploadOneImage('图片上传','#thumb');">
                            <h5 class="btn btn-primary">上传</h5>
                            <if condition="empty($result['stuff_image'])">
                                <img src=""
                                     id="thumb-preview" width="135" style="cursor: hand"/>
                                <else/>
                                <img src="{:cmf_get_image_preview_url($result['stuff_image'])}" id="thumb-preview"
                                     width="135" style="cursor: hand"/>
                            </if>
                        </a>
                        <input type="button" class="btn btn-sm"
                               onclick="$('#thumb-preview').attr('src','');$('#thumb').val('');return false;"
                               value="取消图片">
                    </div>
                </table>
            </div>
            <!--<div class="control-group" >
                <label class="control-label">{:lang('STATUS')}</label>
                <div class="controls">
                    <input type="radio" name="status" value="1"
                    <if ($status)== 1>checked</if>
                    >启用
                    <input type="radio" name="status" value="2"
                    <if ($status)== 2>checked</if>
                    > 关闭
                </div>
            </div>-->
        </fieldset>
        <div class="form-actions">
            <input type="hidden" name="id" value="{$id}"/>
            <input type="hidden" name="pagenum" value="{$pagenum}"/>
            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
            <a class="btn" href="javascript:history.back(-1);">{:lang('BACK')}</a>
        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
<script type="text/javascript">


    function clearNoNum(obj) {
        //先把非数字的都替换掉，除了数字和.
        obj.value = obj.value.replace(/[^\d.]/g, "");
        //必须保证第一个为数字而不是.
        obj.value = obj.value.replace(/^\./g, "");
        //保证只有出现一个.而没有多个.
        obj.value = obj.value.replace(/\.{2,}/g, ".");
        //保证.只出现一次，而不能出现两次以上
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        //保证 数字整数位不大于8位
        if (100000000 <= parseFloat(obj.value))
            obj.value = "";
    }

</script>
</body>
</html>